<template>
    <div class="e-form">
        <div style="width: 100%" class="form">
            <el-form ref="form" :model="formData.facilityInitialize" label-width="200px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="设备名称：">
                             <el-input v-model="formData.facilityInitialize.equipmentName"  readonly>
                                <i slot="suffix" class="el-input__icon el-icon-document-copy" ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="所属机构：">
                            <span>{{ formData.facilityInitialize.orgName }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="原始编号：">
                            <el-input v-model="formData.facilityInitialize.originalNum"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="使用单位：">
                            <el-input v-model="formData.facilityInitialize.useOrg"  readonly>
                                <i slot="suffix" class="el-input__icon el-icon-document-copy" ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="设备类别：">
                              <span>{{ formData.facilityInitialize.equipmentType }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="规格型号：">
                            <el-input v-model="formData.facilityInitialize.specificationModel"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                 <el-row>
                    <el-col :span="12">
                        <el-form-item label="设备属性：">
                            <span>{{ formData.facilityInitialize.equipmentAttribute }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="计量单位：">
                            <span>{{ formData.facilityInitialize.meteringUnit }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                 <el-row>
                    <el-col :span="12">
                        <el-form-item label="设备原值（元）：">
                            <el-input v-model="formData.facilityInitialize.equipmentOriginal"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="设备净值（元）：">
                            <el-input v-model="formData.facilityInitialize.equipmentCompletely"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="购置日期：">
                            <el-date-picker
                                v-model="formData.facilityInitialize.purchaseTime"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd"
                                format="yyyy 年 MM 月 dd 日"
                                :clearable="false"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="验收日期：">
                            <el-date-picker
                                v-model="formData.facilityInitialize.checkDate"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd"
                                format="yyyy 年 MM 月 dd 日"
                                :clearable="false"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="验收地点：">
                            <el-input v-model="formData.facilityInitialize.checkPlace"></el-input>
                        </el-form-item>
                    </el-col>
                   <el-col :span="12">
                        <el-form-item label="生产厂商：">
                            <el-input v-model="formData.facilityInitialize.manufacturer"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                   <el-col :span="12">
                        <el-form-item label="出厂日期：">
                            <el-date-picker
                                v-model="formData.facilityInitialize.productionTime"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd"
                                format="yyyy 年 MM 月 dd 日"
                                :clearable="false"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="出厂编号：">
                            <el-input v-model="formData.facilityInitialize.productionNum"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="规定使用年限：">
                            <el-input v-model="formData.facilityInitialize.stipulateYear"></el-input>
                        </el-form-item>
                    </el-col>
                   <el-col :span="12">
                        <el-form-item label="使用年限：">
                            <el-input v-model="formData.facilityInitialize.useYear"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="累计使用数：">
                            <el-input v-model="formData.facilityInitialize.cumulativeNum"></el-input>
                        </el-form-item>
                    </el-col>
                   <el-col :span="12">
                        <el-form-item label="车牌编号：">
                            <el-input v-model="formData.facilityInitialize.vehicleNum"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="设备状况：">
                            <el-select
                                v-model="formData.facilityInitialize.equipmentCondition"
                                placeholder="请选择"
                            >
                                 <el-option
                                    v-for="(
                                        item,index
                                    ) in equipCondition"
                                    :key="index"
                                    :label="item.label"
                                    :value="item.value"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                   <el-col :span="12">
                        <el-form-item label="设备状态：">
                            <el-select
                                v-model="formData.facilityInitialize.equipmentStatus"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="(
                                        item
                                    ) in equipStatus"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="操作手：">
                             <el-input v-model="formData.facilityInitialize.operation"  readonly>
                                <i slot="suffix" class="el-input__icon el-icon-document-copy" ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="累计折旧（元）：">
                            <el-input v-model="formData.facilityInitialize.accumulativeDepreciation"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                >保存</el-button
            >
            <el-button size="small" @click="handleClose">取消</el-button>
        </div>
    </div>
</template>

<script>
import request from '@/api/equip/equipInit.js'
import { mapState } from 'vuex'
export default {
    data () {
        return {
            formData: {
                //基础信息
                'facilityInitialize': {
                    'acceptanceCheck': '',
                    'accumulativeDepreciation': 0,
                    'checkDate': '',
                    'checkPlace': '',
                    'cumulativeNum': 0,
                    'equipmentAttribute': 0,
                    'equipmentCompletely': 0,
                    'equipmentCondition': 0,
                    'equipmentName': '',
                    'equipmentNo': '',
                    'equipmentOriginal': 0,
                    'equipmentStatus': 0,
                    'equipmentType': '',
                    'equipmentTypeId': '',
                    'facilityInitializeId': '',
                    'manufacturer': '',
                    'meteringUnit': 0,
                    'operation': '',
                    'operationId': '',
                    'orgId': '',
                    'orgName': '',
                    'originalNum': '',
                    'productionNum': '',
                    'productionTime': '',
                    'purchaseTime': '',
                    'specificationModel': '',
                    'stipulateYear': 0,
                    'useOrg': '',
                    'useOrgId': '',
                    'useYear': 0,
                    'vehicleNum': ''
                },
            },
            planNumberVisible: false,
        }
    },
    components: {
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            workStatus: state=>state.equip.equipData.workStatus,
            assessmentLevel: state=>state.equip.equipData.assessmentLevel,
            equipStatus: state => state.equip.equipData.equipStatus, //设备状态
            equipCondition: state => state.equip.equipData.equipCondition, //设备状况

        }),
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>x.value === param)
                return obj.label
            }
        },
    },
    created () {
    },
    mounted () {
        this.userId = localStorage.getItem('userId')
        this.userName = localStorage.getItem('userName')
        const date = new Date()
        this.formData.facilityInitialize.purchaseTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
        this.formData.facilityInitialize.checkDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
        this.formData.facilityInitialize.productionTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
        this.formData.facilityInitialize.orgName = this.userInfo.orgInfo.orgName
        this.formData.facilityInitialize.orgId = this.userInfo.orgInfo.orgId
        this.getDicValue()
    },
    methods: {
        //获取当前使用的字典
        getDicValue () {
            this.$store.dispatch('equip/setEquipStatus')//更新设备状态
        },
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        //保存
        preserve () {
            this.formData.state = 0
            request.equipInitAdd(this.formData).then(()=>{
                this.clientPop('suc', '保存成功', ()=>{ this.$router.push('/equipInitList') })
            })
        },

        //取消
        handleClose () {
            this.$router.go(-1)
        },
    }
}
</script>

<style lang="scss" scoped>
.form {
    margin-top: 10px;
}

.e-table {
    background: #fff;

    /* .top {
    .left {
      padding: 20px;
      padding-top: 0px;
    }
  } */
}

.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>
